<?php
/**
 * $Id$
 */

/**
 * 执行模块
 *
 * @package App
 */
class App_Do extends Tinyask_App
{
	/** 入口函数, 初始化路由器 **/
	public function execute()
	{
		/** 验证路由地址 **/
		$app = trim($this->request->app, '/');
		$objectName = str_replace('/', '_', $app);

		/** 判断是否为plugin **/
		$actionTable = unserialize($this->app('App_Config')->actionTable);
		$isPlugin = in_array($objectName, $actionTable);

		$appName = $isPlugin ? $objectName : 'App_' . $objectName;
		$fileName = ($isPlugin ? $app : 'App/' . $app) . 'php';

		if($isPlugin) {
			require_once $fileName;
			if(class_exists($appName)) {
				$reflectionApp = new ReflectionClass($appName);
				if($reflectionApp->implementsInterface('App_Interface_Do')) {
					$this->app($appName)->action();
					return ;
				}
			}
		}

		throw new Tinyask_App_Exception(_t('请求的地址不存在'), 404);
	}

}
